package com.yedou.controller.subject;

import com.yedou.common.Result;
import com.yedou.entity.dto.SubjectCategoryDTO;
import com.yedou.entity.po.SubjectCategory;
import com.yedou.service.SubjectCategoryService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目分类(SubjectCategory)表控制层
 *
 */
@RestController
@RequestMapping("subjectCategory")
public class SubjectCategoryController {
    /**
     * 服务对象
     */
    @Resource
    private SubjectCategoryService subjectCategoryService;

    /**
     * 分页查询
     *
     */
    @GetMapping
    public Result<List<SubjectCategory>> queryByPage(SubjectCategoryDTO subjectCategory) {
        return Result.ok(this.subjectCategoryService.queryByPage(subjectCategory));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result<SubjectCategory> queryById(@PathVariable("id") Long id) {
        return Result.ok(this.subjectCategoryService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @return 新增结果
     */
    @PostMapping
    public Result<SubjectCategory> add(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
        return Result.ok(this.subjectCategoryService.insert(subjectCategoryDTO));
    }

    /**
     * 编辑数据
     *
     * @return 编辑结果
     */
    @PutMapping
    public Result<SubjectCategory> edit(SubjectCategoryDTO subjectCategoryDTO) {
        return Result.ok(this.subjectCategoryService.update(subjectCategoryDTO));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public Result<Boolean> deleteById(Long id) {
        return Result.ok(this.subjectCategoryService.deleteById(id));
    }


    // 批量插入

    @PostMapping("/batchInsert")
    public Result<List<SubjectCategory>> batchInsert(@RequestBody List<SubjectCategoryDTO> subjectCategoryDTOList){
        return Result.ok(this.subjectCategoryService.batchInsert(subjectCategoryDTOList));
    }

}

